// Copyright 2023 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

#include <Storages/S3/PocoHTTPClient.h>
#include <aws/core/http/HttpClientFactory.h>

namespace Aws::Http
{
class HttpClient;
class HttpRequest;
} // namespace Aws::Http

namespace DB::S3
{
class PocoHTTPClientFactory : public Aws::Http::HttpClientFactory
{
public:
    explicit PocoHTTPClientFactory(const PocoHTTPClientConfiguration & http_cfg);

    ~PocoHTTPClientFactory() override = default;
    [[nodiscard]] std::shared_ptr<Aws::Http::HttpClient> CreateHttpClient(
        const Aws::Client::ClientConfiguration & clientConfiguration) const override;
    [[nodiscard]] std::shared_ptr<Aws::Http::HttpRequest> CreateHttpRequest(
        const Aws::String & uri,
        Aws::Http::HttpMethod method,
        const Aws::IOStreamFactory & streamFactory) const override;
    [[nodiscard]] std::shared_ptr<Aws::Http::HttpRequest> CreateHttpRequest(
        const Aws::Http::URI & uri,
        Aws::Http::HttpMethod method,
        const Aws::IOStreamFactory & streamFactory) const override;

private:
    const Aws::IOStreamFactory null_factory = []() {
        return nullptr;
    };

    PocoHTTPClientConfiguration poco_cfg;
};

} // namespace DB::S3
